﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lincolnwood.Foundation.Common.Data;
using Lincolnwood.Foundation.Common.Data.NHibernate;
using NHibernate;
using NHibernate.Linq;

namespace Lincolnwood.Foundation.SermonLibrary.Data.NHibernate
{
    public class NHibernateBibleVerseRepository : NHibernateReferenceDataRepositoryBase<BibleVerse, short>
    {
        public NHibernateBibleVerseRepository(IUnitOfWork unitOfWork)
            : base((NHibernateUnitOfWork)unitOfWork)
        { }

        public BibleVerse FindByBookChapterAndVerse(short bibleBookId, short bookChapterNumber, short chapterVerseNumber)
        {
            BibleVerse match = (from v in UnitOfWork.Session.Query<BibleVerse>() 
                                where (v.Book.Id == bibleBookId) 
                                && (v.Chapter == bookChapterNumber) 
                                && (v.VerseNumber == chapterVerseNumber) select v).FirstOrDefault<BibleVerse>();

            return match;
        }
    }
}
